<template>
  <div class="app-container">
    <!-- 查询 -->
    <div class="filter-container">
      <el-row :gutter="0">
        <el-form :inline="true" class="search-form">
          <el-form-item label="名称">
            <el-input v-model="query.name" class="filter-item" placeholder="请输入名称" clearable/>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="query.range_date"
              type="daterange"
              class="filter-item"
              style="width: 240px;"
              range-separator="-"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </el-form-item>
          <el-form-item>
            <el-button class="" type="primary" icon="el-icon-search" @click="search">查询</el-button>
            <el-button class="" type="success" icon="el-icon-refresh-right" plain @click="refresh()">刷新</el-button>
          </el-form-item>

          <el-form-item style="float: right">

          </el-form-item>
        </el-form>
      </el-row>
    </div>
    <!-- 列表 -->
    <el-table ref="tableRef" v-loading="loading" :data="datas" :max-height="height" style="width: 100%" border @sort-change="sorting">
      <el-table-column width="60px" align="center">
        <template v-slot="props">
          <el-radio :value="selected.id" :label="props.row.id" @change="handleSelect(props.row)">{{""}}</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="avatar" label="头像" min-width="70" align="center">
        <template slot-scope="scope">
          <el-image v-if="scope.row.full_avatar" :src="scope.row.full_avatar" :preview-src-list="[scope.row.full_avatar]"/>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="名称" min-width="120" align="center" show-overflow-tooltip/>
      <el-table-column prop="mobile" label="手机号" min-width="120" align="center" show-overflow-tooltip/>
      <el-table-column prop="created_at" label="创建时间" min-width="160" align="center" sortable="custom"/>
      <!--<el-table-column label="操作" min-width="80" align="center" fixed="right">
        <template slot-scope="{ row }">
          <el-button type="info" icon="el-icon-s-data" size="mini" @click="doSelect(row)">选择</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <pagination v-show="total > 0" :total="total" :page.sync="query.page" :limit.sync="query.limit" @pagination="list"/>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" icon="el-icon-check" @click="confirmCBK">确认</el-button>
    </div>
  </div>
</template>

<script>
import screenHeight from '@/utils/screen-height'
import Pagination from '@/components/Pagination'
import {list} from '@/api/admin/member'

export default {
  name: 'RadioUser',
  components: {Pagination},
  props: {

  },
  data() {
    return {
      height: 680,
      loading: false,
      datas: [],
      total: 0,
      query: {
        page: 1,
        limit: 20,
        name: '',
        range_date: []
      },

      selected: {}
    }
  },
  watch: {

  },
  created() {
    this.height = screenHeight()
    this.selected = {}
    this.list()
  },
  methods: {
    // 列表
    list() {
      this.loading = true
      list(this.query).then(res => {
        this.datas = res.data.data
        this.total = res.data.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询
    search() {
      this.query.page = 1
      this.list()
    },
    // 刷新
    refresh() {
      this.query = this.$options.data().query
      this.list()
    },
    // 排序
    sorting(sort) {
      this.query.sort_field = sort.prop
      this.query.sort_value = ''
      if (sort.order === 'ascending') {
        this.query.sort_value = 'asc'
        this.list()
      }
      if (sort.order === 'descending') {
        this.query.sort_value = 'desc'
        this.list()
      }
    },

    handleSelect(row) {
      this.selected = row
    },

    // 选中回调
    confirmCBK() {
      this.$emit('radioCallback', this.selected)
    }
  }
}
</script>

<style scoped>
.dialog-footer {
  text-align: right;
}
.el-table .el-image {
  width: 40px;
  height: 40px;
}
</style>
